package com.kinon.market.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kinon.market.R;
import com.kinon.market.entity.OrderdetialEntity;
import com.kinon.market.tools.HttpTools;

import java.util.ArrayList;

/**
 * 订单item
 */

public class DingdandetialAdapter extends BaseAdapter {
    Context context;
    ArrayList<OrderdetialEntity> orderdetialList;
    HttpTools httpTools = null;
    View iscatview = null;

    public DingdandetialAdapter(Context context, ArrayList<OrderdetialEntity> orderdetialList) {
        super();
        this.context = context;
        this.orderdetialList = orderdetialList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return orderdetialList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return orderdetialList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_dingdanshangpin, null);
            handle.tv_name = (TextView) view.findViewById(R.id.tv_name);
            handle.tv_amount = (TextView) view.findViewById(R.id.tv_shuliang);
            handle.tv_price = (TextView) view.findViewById(R.id.tv_price);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }
        handle.tv_name.setText(orderdetialList.get(position).getName());
        handle.tv_amount.setText("" + (int) Double.parseDouble(orderdetialList.get(position).getAmount()));
        handle.tv_price.setText("￥" + orderdetialList.get(position).getPrice());

        return view;
    }

    class ViewHandle {
        /**
         * 商品名
         */
        TextView tv_name;
        /**
         * 数量
         */
        TextView tv_amount;
        /**
         * 价格
         */
        TextView tv_price;
    }


}
